package com.aaa.controller;

import com.aaa.entity.Author;
import com.aaa.service.impl.AuthorServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("author")
@RestController
public class AuthorController {
    @Resource
    AuthorServiceImpl authorService;

    @RequestMapping("find")
    public List<Author> find(){
        return authorService.find();
    }


    @ResponseBody
    @RequestMapping("add")
    public int add(Author author){
        return authorService.add(author);
    }

    @ResponseBody
    @RequestMapping("update")
    public int update(Author author){
        return authorService.update(author);
    }

    @ResponseBody
    @RequestMapping("delete")
    public int delete(Integer id){
        return authorService.delete(id);
    }

    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> find(Integer pageSize, Integer pageNum){
        Map<String, Object> map = new HashMap<>();
        List<Author> userList = authorService.findpage(pageSize, pageSize*pageNum );
        Integer TotalNum = authorService.findcount();
        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }


}
